from etgui import *
from PageLayout import *
def MakeView():
	"""Create the GUI elements"""

	view=MakePageLayout(
		eVObjHExpand|eVObjVCenter,
		PotGuiToggleButton("Toggle1", "Toggle 1"),
		PotGuiToggleButton("Toggle2", "Toggle 2"),
		PotGuiToggleButton("Toggle3", "Toggle 3"),
	)
	return view

import copy
# important: keep one copy of the dialog
class MyModel(DictPyModel):
	def __init__(self):
		DictPyModel.__init__(self)
		# A instance variable to carry the state.
		# This is updated when OK or Apply is pressed.
		# Cancel restores the DictPyModel.dict from those values
		self.result={}
	def DoSetValue(self,path,value):
		# here is the trick:
		# when Toggle1 is set to 1 we set Toggle3 and Toggle4 to 0
		if path=="Toggle1" and value==1:
			self.SetValue("Toggle2",0)
			self.SetValue("Toggle3",0)
		if (path=="Toggle2" or path=="Toggle3" ) and value==1:
			self.SetValue("Toggle1",0)
		# do not forget to call the superclass method
		return DictPyModel.DoSetValue(self,path,value)
	def DoApply(self):
		# Called when OK or Apply is pressed.
		# Here, we remember a copy of the data dict
		# We have to do a deepcopy (else we would refer to the same dict!)
		self.result=copy.deepcopy(self.dict)
		print "DoApply:",self.result
	def DoCancel(self):
		# Called when Cancel is pressed.
		# We restore the original content of the dict 
		self.dict=copy.deepcopy(self.result)
		print "Cancel:",self.result

gDialog=None
def Show():
	global gDialog,gModel
	if not gDialog:
		# create the dialog once!
		gModel=MyModel()
		gDialog=MakeOkCancelDialog(
			"My Dialog",        # the title of the dialog
			gModel,
			MakeView(),  
			ActionButton(CmdNo.cIdOk,"OK",default=1), # make OK button the default, calls Apply implicilely
			ActionButton("Apply",action=gModel.Apply),# tricky action is gModel.Apply
			ActionButton(CmdNo.cIdCancel,"Cancel")    # calls Cancel implicilely
		)
	gDialog.ShowUnderMouse()
if __name__=="__main__":
	# When we run the dialog from the Python dialog within sniff
	# Show the dialog multiple times.
	for i in range(3):
		Show()
